package com.nf.practice.distincttest;

import org.junit.jupiter.api.Test;
import java.util.*;

public class DisMapTest2 {

    @Test
    public void test1() {
        //初始化数据
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, Object> result = new HashMap<String, Object>();
        //添加数据result1
        result.put("ruleVariableDesc", "手机状态异常");
        resultList.add(result);
        //添加数据result2
        Map<String, Object> result2 = new HashMap<String, Object>();
        result2.put("ruleVariableDesc", "RH信用不良");
        resultList.add(result2);
        //添加数据result3
        Map<String, Object> result3 = new HashMap<String, Object>();
        result3.put("ruleVariableDesc", "身份证命中执行信息");
        resultList.add(result3);
        //添加数据result4
        Map<String, Object> result4 = new HashMap<String, Object>();
        result4.put("ruleVariableDesc", "单位地址比对相同");
        resultList.add(result4);
        //添加数据result5
        Map<String, Object> result5 = new HashMap<String, Object>();
        result5.put("ruleVariableDesc", "RH贷记卡使用率过高");
        resultList.add(result5);
        //添加数据result6
        Map<String, Object> result6 = new HashMap<String, Object>();
        result6.put("ruleVariableDesc", "RH信用不良");
        resultList.add(result6);
        //添加数据result7
        Map<String, Object> result7 = new HashMap<String, Object>();
        result7.put("ruleVariableDesc", "RH贷记卡使用率过高");
        resultList.add(result7);
        //添加数据result8
        Map<String, Object> result8 = new HashMap<String, Object>();
        result8.put("ruleVariableDesc", "RH信用不良");
        resultList.add(result8);

        System.out.println("old: " + resultList);

//        for (int i = 0; i < resultList.size(); i++) {
//            Map<String, Object> r = resultList.get(i);
//            Object value = r.get("ruleVariableDesc");
//            System.out.println(value);
//            for (int j = resultList.size()-1; j > i; j--) {
//                Map<String, Object> r2 = resultList.get(j);
//                if (value.equals(r2.get("ruleVariableDesc"))) {
//                    resultList.remove(j);
//                }
//            }
//        }


        Map<String, Object> hashMap = new HashMap<>();
        List<Map<String, Object>> newlist = new ArrayList<>();
        for (int i = 0; i < resultList.size(); i++) {
            Map<String, Object> r = resultList.get(i);
            Object value = r.get("ruleVariableDesc");
            System.out.println(value);
            if(!hashMap.containsValue(value)){
                hashMap.put("ruleVariableDesc"+i,value);
                newlist.add(r);
            }
        }
        System.out.println("new: " + newlist);

//        System.out.println("new: " + resultList);

    }

}
